{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "URL = 'https://raw.githubusercontent.com/ajduberstein/oakland_point_cloud/master/%s'\n",
    "DATA_URL = URL % 'lidar_chunks_1.csv'\n",
    "LOOKUP_URL = URL % 'ground_truth_label.csv'\n",
    "lidar = pd.read_csv(DATA_URL)\n",
    "lookup = pd.read_csv(LOOKUP_URL)\n",
    "lidar = lidar.merge(lookup)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print('Number of points:', lidar.count())\n",
    "lidar.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydeck import data_utils\n",
    "\n",
    "color_lookup = data_utils.assign_random_colors(lidar['label_name'])\n",
    "\n",
    "lidar['color'] = lidar.apply(lambda row: color_lookup.get(row['label_name']), axis=1)\n",
    "\n",
    "lidar.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydeck import Deck, Layer\n",
    "\n",
    "lidar['coordinates'] = lidar.apply(lambda x: [x['x'], x['y'], x['z']], axis=1)\n",
    "\n",
    "point_cloud = Layer(\n",
    "    'PointCloudLayer',\n",
    "    lidar[['coordinates', 'label_name', 'color']],\n",
    "    get_position='coordinates',\n",
    "    get_normal=[0, 0, 1],\n",
    "    get_color='color',\n",
    "    radius_pixels=4)\n",
    "\n",
    "r = Deck(\n",
    "    point_cloud,\n",
    "    initial_view_state=pdk.ViewState(\n",
    "        fov=2,\n",
    "        rotation_x=0,\n",
    "        max_zoom=100,\n",
    "        coordinate_system='COORDINATE_SYSTEM.METERS',\n",
    "        rotation_orbit=0,\n",
    "        orbit_axis='Y',\n",
    "        zoom=1,\n",
    "        distance=10,\n",
    "        min_distance=1,\n",
    "        max_distance=100\n",
    "    ),\n",
    "    map_style=None\n",
    ")\n",
    "r.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
